package com.sams.controller;

import com.alibaba.fastjson.JSON;
import com.sams.pojo.Convenient;
import com.sams.service.ConvenientService;
import com.sams.util.CommonUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/edit_apply")
public class ConvenientUpdate extends HttpServlet {
    private ConvenientService convenientService=new ConvenientService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*接收页面传来的成绩录入信息*/
        BufferedReader reader = request.getReader();
        String params = reader.readLine();
        /*将这个jason字符串转换*/
        Convenient convenient = JSON.parseObject(params, Convenient.class);
        System.out.println(convenient.toString());
        HttpSession session = request.getSession();
        String user_name = (String)session.getAttribute("user_name");
        convenient.setService_people(user_name);
        boolean updatedata = convenientService.updatedata(convenient);
        if (updatedata){
            response.getWriter().write("success");
        }else {
            response.getWriter().write("no");
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
